<%--
  Created by IntelliJ IDEA.
  User: cola
  Date: 2021/4/25
  Time: 20:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form name="form1" action="" onsubmit="return false" method="post">
    <label for="">用户名:<input type="text" name="username"></label><br>
    <label for="">密码:<input type="password" name="password"></label><br>
    <label for="">年龄:<input type="text" name="age"></label><br>
    <label for="">邮箱:<input type="text" name="email"></label><br>
    <label for="">省份:<input type="text" name="address.province"></label><br>
    <label for="">城市:<input type="text" name="address.city"></label><br>
    <label for="">生日:<input type="text" name="birthday"></label><br>
    <button>保存</button>
</form>
<h1>请录入用户信息:格式为</h1>
<p>helen-18-123@qq.com</p>
<form name="form2" action="saveuser" method="post">
    <textarea name="user" id="user" cols="100" rows="10"></textarea><br>
    <%--<label for="">生日:<input type="text" name="birthday"></label><br>--%>
    <button>保存</button>
</form>
<h1>使用json提交用户数据</h1>
<form name="form3" id="form3" action="# #"onsubmit="false" method="post">
    <label for="">用户名:<input type="text" name="username" id="username"></label><br>
    <label for="">密码:<input type="password" name="password" id="password"></label><br>
    <label for="">年龄:<input type="text" name="age" id="age"></label><br>
    <button type="button" id="saveBtn" name="saveBtn">保存</button>
</form>

<hr/>
<h1>文件上传</h1>
<form action="fileupload" method="post" enctype="multipart/form-data">
    <label for=""><input type="file" name="file" id="file"></label>
    <label for=""><input type="text" name="desc" id="desc"></label>
    <button>上传</button>
</form>
<%--<script src="${pageContext.request.contextPath}/lib/js/vue.js"></script>--%>
<script type="text/javascript" src="${pageContext.request.contextPath}/lib/js/jquery-3.6.0.min.js"></script>
<script>
    $(function () {
        console.log("getguid函数执行了");
        $('#saveBtn').click(function () {
            var row={
                username: $('#username').val(),
                password: $('#password').val(),
                age:$('#age').val(),
            };
            //alert(JSON.stringify(row));
            $.ajax({
                type: "POST",
                url: 'user-json',
                contentType:'application/json;charset=utf-8',
                data: JSON.stringify(row),
                success: function(data) {
                    alert(data);
                }
            });
        });
    });
</script>
</body>
<script>

</script>
</html>